var maxProfit = function(prices) {
    let sum = 0
    for (let i = 0; i < prices.length; i++) {
        let val = prices[i+1] - prices[i]
        if (val > 0) {
            sum += val
        }
    }
    return sum
};

let prices = [7,1,5,3,6,4]
console.log(maxProfit(prices));
